package com.bootdo.system.controller;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.bootdo.common.controller.BaseController;
import com.bootdo.system.service.FileService;

import io.swagger.annotations.Api;

@RequestMapping("/sys/file")
@Controller
@Api(value = "/sys/file", description = "附件操作接口")
public class FileController  extends BaseController {
	
	@Autowired
	FileService fileService;
	
	 @RequestMapping(value = "/upload", method = RequestMethod.POST)
	 @ResponseBody
	 public Map<String, Object> headImgUpload(HttpServletRequest request,MultipartFile file) throws Exception {
	   Map<String, Object> value = new HashMap<String, Object>();
	   value.put("success", true);
	   value.put("errorCode", 0);
	   value.put("errorMsg", "");
	   try {
	     String head = fileService.updateHead(file, 4);//此处是调用上传服务接口，4是需要更新的userId 测试数据。
	     value.put("data", head);
	   } catch (Exception e) {
	     e.printStackTrace();
	     value.put("success", false);
	     value.put("errorCode", 200);
	     value.put("errorMsg", "图片上传失败");
	   }
	   return value;
	 }

}
